//
//  MCTrainListViewVc.swift
//  MCBodyBuildingPro
//
//  Created by Renlvshijie on 2023/6/17.
//

import UIKit
import Kingfisher
import QMUIKit

class MCTrainListViewVc: MCBaseVc {

    public var detailInfoList:Array<MCStartXunLianActionPlanDetailList?> = []
    
    
    @IBOutlet weak var trainActionTableView: UITableView!
    
    
    private let trainActionTableViewIdentifier = "trainActionTableViewIdentifier"
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor.white
       
        self.trainActionTableView.dataSource = self
        self.trainActionTableView.delegate = self
        
        self.trainActionTableView.register(UINib(nibName: "MCTrainListTableCell", bundle: Bundle.main), forCellReuseIdentifier: trainActionTableViewIdentifier)
        self.trainActionTableView.rowHeight = 75
    
        
    }

    //
    @IBAction func backSender(_ sender: UIButton) {
        self.dismiss(animated: true) {
            
        }
    }
}

extension MCTrainListViewVc:UITableViewDataSource,UITableViewDelegate {
    func numberOfSections(in tableView: UITableView) -> Int {
        return self.detailInfoList.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        
        let detailActionList = self.detailInfoList[section]?.actionPlanDetailActionList
        
        return detailActionList?.count ?? 0
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell:MCTrainListTableCell = tableView.dequeueReusableCell(withIdentifier: trainActionTableViewIdentifier, for: indexPath) as! MCTrainListTableCell
        
        let trainInfoList = self.detailInfoList[indexPath.section]
        
        let trainActionList = trainInfoList?.actionPlanDetailActionList?[indexPath.row]
        
        cell.headerImageView.kf.setImage(with: URL(string: trainActionList?.previewUrl ?? ""))
        cell.titleInfoLabel.text = trainActionList?.actionName ?? ""
        cell.subTitleLabel.text = "\(indexPath.section + 1)组 \(String(describing: (trainInfoList?.breakTime ?? 0)!))s"
        
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 40
    }
    
    
    
    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let headerView = MCHeaderTrainListView.initHeaderView()
        
        headerView.headerInfoLabel.text = "第\(section + 1)组"
        
        return headerView
        
    }
    
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 40
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let footerViewTrainListView = MCFooterTrainListView.initHeaderView()
        
        let trainInfoList = self.detailInfoList[section]
        
        footerViewTrainListView.footerTitleLabel.text = "休息\(String(describing: (trainInfoList?.breakTime)!))s"
        
        return footerViewTrainListView
        
    }
    
    
}


